package com.sunlands.zlcx.usercenter.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sunlands.zlcx.usercenter.domain.UsersStudyInfoDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(value = "学习生活VO")
public class UsersStudyInfoVO implements Serializable {

    private static final long serialVersionUID = 7458892443946061641L;
    private Long id;

    /**
     * 学习生活名称
     */
    @ApiModelProperty(value = "学习生活名称")
    private String studyInfoName;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id")
    private Long userId;

    @ApiModelProperty(value = "学习内容id")
    private Long contentId;

    /**
     * 目标id
     */
    @ApiModelProperty(value = "目标id")
    private Long targetId;

    /**
     * 状态
     */
    @ApiModelProperty(value = "状态")
    private Integer status;


    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    /**
     * 实际学习秒数
     */
    @ApiModelProperty(value = "实际学习秒数")
    private Integer studyMinuteSeconds;

    /**
     * 关联id
     */
    private Long relateId;

    /**
     * 星期几
     */
    @ApiModelProperty(value = "周几")
    private String week;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    /**
     * {@link com.sunlands.zlcx.usercenter.domain.UsersStudyInfoDO.TypeEnums}
     * 类型id
     */
    @ApiModelProperty(value = "类型id,1学习计时,5连麦计时;11开始学习计时,13学习计时暂停,14学习计时继续,15开始连麦计时")
    private Integer type;

    /**
     * {@link com.sunlands.zlcx.usercenter.domain.UsersStudyInfoDO.TypeEnums}
     * 类型名称
     */
    @ApiModelProperty(value = "类型名称")
    private String typeName;

    /**
     * 统计时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date countTime;

    /**
     * 这个字段虽然命名为lianMaiId，
     * 但是因为计时自习室中也使用到了此id
     * 故lianMaiId在计时自习室学习时含义为座位id
     * 在连麦学习时含义为pulishId
     */
    @ApiModelProperty(value = "连麦id")
    private Long lianMaiId;
    /**
     * roomId在计时自习室学习时含义为计时自习室id
     * 在连麦学习时含义为连麦房间id
     */
    @ApiModelProperty(value = "连麦房间id")
    private Long roomId;

    @ApiModelProperty(value = "暂停时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date pauseTime;

    @ApiModelProperty(value = "继续时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date continueTime;

    @ApiModelProperty(value = "用户设定学习时间，秒")
    private Long userSetTime = null;

    public static UsersStudyInfoVO from(UsersStudyInfoDO usersStudyInfoDO) {
        return Objects.isNull(usersStudyInfoDO)? null : UsersStudyInfoVO.builder().id(usersStudyInfoDO.getId())
                .createTime(usersStudyInfoDO.getCreateTime())
                .startTime(usersStudyInfoDO.getStartTime())
                .endTime(usersStudyInfoDO.getEndTime())
                .status(usersStudyInfoDO.getStatus())
                .userId(usersStudyInfoDO.getUserId())
                .targetId(usersStudyInfoDO.getTargetId())
                .studyInfoName(usersStudyInfoDO.getStudyInfoName())
                .studyMinuteSeconds(usersStudyInfoDO.getStudyMinutes()*60)
                .week(usersStudyInfoDO.getWeek())
                .type(usersStudyInfoDO.getType())
                .typeName(UsersStudyInfoDO.TypeEnums.create(usersStudyInfoDO.getType()).getTitle())
                .relateId(usersStudyInfoDO.getRelateId())
                .countTime(usersStudyInfoDO.getCountTime())
                .build();
    }
}
